<template>
  <div style="height: 100%">
    <mescroll-vue
      ref="mescroll"
      :down="mescrollDown"
      :up="mescrollUp"
      @init="mescrollInit"
    >
      <div class="msgContainer">
        <img
          v-if="currentConversation.userProfile.avatar"
          :src="$fnc.getImgUrl(currentConversation.userProfile.avatar)"
          alt=""
        />
        <img
          v-else
          :src="
            baseData.sex == 2
              ? require('../../../assets/img/sex2.png')
              : require('../../../assets/img/sex1.png')
          "
          alt=""
        />
        <!-- <div class="msgData">
          <div>
            <span>0</span>
            <span>平台浏览量</span>
          </div>
          <div>
            <span>0%</span>
            <span>复购意向</span>
          </div>
          <div>
            <span>0%</span>
            <span>信息完善</span>
          </div>
        </div> -->
        <div class="baseMsgs">
          <div class="itemData">
            <div class="leftTitle">
              <span class="line"></span>
              <span>基本信息</span>
            </div>
            <div class="rightEdit">
              <i class="el-icon-user"></i>
              <span @click="seeDetail">详情</span>
            </div>
          </div>
          <p class="itemBaseData">
            昵称：{{ chat_userinfo.nickname || "----" }}【{{
              chat_userinfo.username
            }}】
          </p>
          <p class="itemBaseData">
            所在地：{{
              chat_userinfo.agent_province +
                chat_userinfo.agent_city +
                chat_userinfo.agent_area +
                chat_userinfo.agent_town || "----"
            }}
          </p>
          <!-- <p class="itemBaseData">备注：前端</p> -->
          <div class="itemData">
            <div class="leftTitle">
              <span class="line"></span>
              <span>雇主行为轨迹</span>
            </div>
          </div>
        </div>
      </div>
      <div class="records">
        <div
          v-show="footList.length > 0 && chat_userinfo.id"
          v-for="(item, index) in footList"
          :key="index"
          class="knowItem"
        >
          <div class="titles">
            {{ item.title | limitText }}
            <div @click="copyLink(item)" class="copyBtn">
              <i class="el-icon-copy-document"></i>复制链接
            </div>
          </div>
          <div class="timeData">
            <div>浏览时间：{{ item.created_time | getTimeFormat }}</div>
            <!-- <div>浏览时长：55‘’20</div> -->
            <div>浏览类型：{{ item.types }}</div>
            <!-- <div class="copyBtn">复制链接</div> -->
          </div>
        </div>
        <div
          class="noneData"
          v-show="footList.length == 0 || !chat_userinfo.id"
        >
          <img src="@/assets/img/empty.png" alt="" />
          <span>该用户暂无行为轨迹~</span>
        </div>
      </div>
    </mescroll-vue>
  </div>
</template>

<script>
import { mapState } from "vuex";

import MescrollVue from "mescroll.js/mescroll.vue"; //下拉组件
export default {
  components: {
    MescrollVue,
  },
  props: {
    baseData: Object,
  },
  data() {
    return {
      mescroll: null, // mescroll实例对象
      mescrollDown: {
        mustToTop: true,
      }, //下拉刷新的配置. (如果下拉刷新和上拉加载处理的逻辑是一样的,则mescrollDown可不用写了)
      mescrollUp: {
        // 上拉加载的配置.
        callback: this.upCallback, // 上拉回调,此处简写; 相当于 callback: function(page, mescroll) { }
        //以下是一些常用的配置,当然不写也可以的.
        page: {
          num: 0, //当前页 默认0,回调之前会加1; 即callback(page)会从1开始
          size: 10, //每页数据条数,默认10
        },
        htmlNodata: '<p class="upwarp-nodata">-- END --</p>',
        noMoreSize: 1, //如果列表已无数据,可设置列表的总数量要大于5才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看这就是为什么无更多数据有时候不显示的原因
        // toTop: {
        //   //回到顶部按钮
        //   src: "./static/mescroll/mescroll-totop.png", //图片路径,默认null,支持网络图
        //   offset: 1000, //列表滚动1000px才显示回到顶部按钮
        // },
        empty: {
          //列表第一页无任何数据时,显示的空提示布局; 需配置warpId才显示
          warpId: "", //父布局的id (1.3.5版本支持传入dom元素)
          icon: "./static/mescroll/mescroll-empty.png", //图标,默认null,支持网络图
          tip: "暂无相关数据~", //提示
        },
      },
      footList: [], // 足迹
    };
  },
  filters: {
    limitText(val) {
      if (val.length > 30) {
        return val.slice(0, 30) + "...";
      } else {
        return val;
      }
    },
  },
  computed: {
    ...mapState({
      chat_userinfo: (state) => state.conversation.chat_userinfo,
      mobileWebSite: (state) => state.mobileWebSite,
      currentConversation: (state) => state.conversation.currentConversation,
    }),
    showCurrentConversation() {
      return !!this.currentConversation.conversationID;
    },
  },
  watch: {
    chat_userinfo() {
      // console.log("aaaaaaaa");
      this.mescroll.resetUpScroll();
    },
  },
  mounted() {},
  beforeRouteEnter(to, from, next) {
    // 如果没有配置回到顶部按钮或isBounce,则beforeRouteEnter不用写
    next((vm) => {
      // 找到当前mescroll的ref,调用子组件mescroll-vue的beforeRouteEnter方法
      vm.$refs.mescroll && vm.$refs.mescroll.beforeRouteEnter(); // 进入路由时,滚动到原来的列表位置,恢复回到顶部按钮和isBounce的配置
      // 进入路由时,滚动到原来的列表位置,恢复回到顶部按钮和isBounce的配置
    });
  },
  beforeRouteLeave(to, from, next) {
    // 如果没有配置回到顶部按钮或isBounce,则beforeRouteLeave不用写
    // 找到当前mescroll的ref,调用子组件mescroll-vue的beforeRouteLeave方法
    this.$refs.mescroll && this.$refs.mescroll.beforeRouteLeave(); // 退出路由时,记录列表滚动的位置,隐藏回到顶部按钮和isBounce的配置
    // 退出路由时,记录列表滚动的位置,隐藏回到顶部按钮和isBounce的配置
    next();
  },
  methods: {
    copyLink(item) {
      let url = this.mobileWebSite;
      if (item.types == "浏览新闻") {
        url += `pages/news/newsdetail/newsdetail?id=${item.pid}`;
      } else if (item.types == "主题页面") {
        url = url;
      } else if (item.types == "浏览商品") {
        url += `pages/shop/shopdetail/shopdetail?id=${item.pid}`;
      } else if (item.types == "商家店铺") {
        url += `pages/shop/supplier/supplier?id=${item.pid}`;
      } else if (item.types == "内容付费") {
        url += `page/study?id=${item.pid}`;
      } else if (item.types == "音频课程") {
        url += `page/temp1?id=${item.pid}`;
      } else if (item.types == "小说") {
        url += `page/bookmsg?id=${item.pid}`;
      }
      let oInput = document.createElement("input");
      oInput.value = url;
      document.body.appendChild(oInput);
      oInput.select();
      document.execCommand("Copy");
      oInput.className = "oInput";
      oInput.style.display = "none";
      this.$fnc.alertSuccess("复制成功");
    },
    seeDetail() {
      this.$router.push(`/index/user/user_info?id=${this.chat_userinfo.id}`);
    },
    mescrollInit(mescroll) {
      this.mescroll = mescroll; // 如果this.mescroll对象没有使用到,则mescrollInit可以不用配置
    },

    upCallback(page, mescroll) {
      if (!this.chat_userinfo.id) {
        mescroll.endSuccess(0);
        return;
      }
      this.$api.getPage
        .get_footprintlist({
          page: page.num,
          username: this.chat_userinfo.username,
        })
        .then((res) => {
          if (res.data.code == 200) {
            let arr = res.data.result.data;
            // 如果是第一页需手动置空列表
            if (page.num === 1) this.footList = [];
            // 下拉刷新
            // 把请求到的数据添加到列表
            this.footList = this.footList.concat(arr);
            // 数据渲染成功后,隐藏下拉刷新的状态
            this.$nextTick(() => {
              mescroll.endSuccess(arr.length);
            });
          } else {
            mescroll.endErr();
          }
        });
    },
  },
};
</script>

<style lang="less" scoped>
.msgContainer {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  align-items: center;
  padding-top: 20px;
  > img {
    width: 125px;
    height: 125px;
    border: 1px solid rgb(212, 212, 212);
    box-shadow: 0 0 10px #ccc;
  }
  .msgData {
    display: flex;
    width: 100%;
    justify-content: space-between;
    align-items: center;
    padding: 0 25px;
    margin-top: 15px;
    > div {
      display: flex;
      flex-direction: column;
      > span {
        margin: 3px 0;
      }
      > span:nth-child(1) {
        color: rgb(40, 40, 40);
        font-weight: bold;
      }
      > span:nth-child(2) {
        color: rgb(153, 153, 153);
      }
    }
  }
  .baseMsgs {
    width: 100%;
    padding: 5px 10px;
    > .itemData {
      display: flex;
      width: 100%;
      justify-content: space-between;
      margin-top: 20px;
      .leftTitle {
        display: flex;
        align-items: center;
        > span:nth-child(1) {
          color: rgb(80, 141, 237);
          width: 5px;
          height: 15px;
          display: block;
          background-color: rgb(80, 141, 237);
          margin-right: 5px;
        }
        > span:nth-child(2) {
          color: rgb(21, 21, 21);
          font-weight: bold;
          font-size: 17px;
        }
      }
      .rightEdit {
        color: rgb(65, 131, 239);
        cursor: pointer;
      }
    }
    .itemBaseData {
      text-align: left;
      margin: 10px 0 5px 0;
    }
    .record {
      text-align: left;
      color: rgb(164, 164, 164);
      margin-top: 10px;
    }
    .btns {
      display: flex;
      width: 100%;
      justify-content: flex-start;
      margin-top: 10px;
      button {
        padding: 8px 20px;
      }
    }
  }
}
.records {
  // height: 230px;
  overflow: auto;
  overflow: hidden;
}
.knowItem {
  text-align: left;
  border-bottom: 1px solid rgb(230, 230, 230);
  padding: 10px 10px;
  font-size: 14px;
  .titles {
    height: 50px;
    position: relative;
    line-height: 25px;
    color: rgb(101, 101, 101);
    .copyBtn {
      position: absolute;
      background-color: rgb(64, 158, 255);
      color: #fff;
      right: 0px;
      bottom: 2px;
      padding: 0px 10px;
      line-height: 20px;
      border-radius: 15px;
      font-size: 12px;
      cursor: pointer;
      i {
        margin-right: 2px;
      }
    }
  }
  .timeData {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: rgb(132, 132, 131);
    .copyBtn {
      // position: absolute;
      background-color: rgb(64, 158, 255);
      color: #fff;
      right: 0px;
      bottom: 2px;
      padding: 0px 10px;
      border-radius: 15px;
      font-size: 12px !important;
      cursor: pointer;
    }
  }
}

.noneData {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: #999;
}
</style>